import sys
from PyQt5.QtGui import QPixmap,QPainter
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication,QMessageBox,QWidget
from app.uis.Ui_login import Ui_Form
from main import MyWindow
class CLogin(QWidget,Ui_Form):
    def __init__(self,parent=None):
        super(CLogin,self).__init__(parent)
        self.setupUi(self)
        self.pushButton.clicked.connect(self.word_get)
        self.pushButton_2.clicked.connect(self.close)
    def paintEvent(self, event):# set background_img
        painter = QPainter(self)
        painter.drawRect(self.rect())
        pixmap = QPixmap("./bg.jpg")#换成自己的图片的相对路径
        painter.drawPixmap(self.rect(), pixmap)
    
    #重写回车事件
    def keyPressEvent(self, event):
        #这里event.key（）显示的是按键的编码
        if str(event.key())=='16777220':#回车
            self.word_get()
    def word_get(self):
        login_user = self.lineEdit.text()
        login_password = self.lineEdit_2.text()
        if login_user == 'admin' and login_password == '123456':
            main.show()
            self.close()
        else:
            QMessageBox.warning(self,"警告","用户名或密码错误！",QMessageBox.Yes)
# pyinstaller -F -w -i 2.ico login.py (带登录界面)
if __name__ == '__main__': 
    app = QApplication(sys.argv)
    main = MyWindow()
    cLogin = CLogin()
    cLogin.show()
    sys.exit(app.exec_())